package com.zking.ssm.NH.controller;


import com.zking.ssm.NH.model.ThotelAssess;
import com.zking.ssm.NH.service.IThotelAssessService;
import com.zking.ssm.util.JsonData;
import com.zking.ssm.util.PageBean;
import org.apache.commons.beanutils.ConvertUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/lxld")
public class ThotelAssessController {

    @Autowired
    private IThotelAssessService thotelAssessService;

    private ThotelAssess thotelAssess;


    @ModelAttribute
    public void init(Model model){
        ThotelAssess thotelAssess=new ThotelAssess();
        model.addAttribute("thotelAssess",thotelAssess);
    }

    @RequestMapping(value = "/lista")
    @ResponseBody
    public JsonData lista(ThotelAssess thotelAssess, PageBean pageBean) {
        List<ThotelAssess> bookList =thotelAssessService.lista(thotelAssess, pageBean);
        JsonData jsonData = new JsonData();
        jsonData.setCode(0);
        jsonData.setMessage("查询成功");
        jsonData.setResult(bookList);
        return jsonData;
    }


    @RequestMapping(value = "/insert")
    @ResponseBody
    public JsonData insert(ThotelAssess thotelAssess) {
//        long l = System.currentTimeMillis();
//        thotelFacility.setCreateTime(1);
        System.out.println(thotelAssess+"这是数据，+++++++++++++++++++++++++");
        thotelAssessService.insertSelective(thotelAssess);
        JsonData jsonData = new JsonData();
        jsonData.setCode(0);
        jsonData.setMessage("添加成功");
        return jsonData;
    }

    @RequestMapping(value = "/deletepiliang")
    @ResponseBody
    public JsonData deletepiliang(ThotelAssess thotelAssess) {
        System.out.println("thotelAssess"+thotelAssess);
        String[] ids= thotelAssess.getIds().split(",");
        System.out.println("ids"+ids);
        Integer[] aa = (Integer[]) ConvertUtils.convert(ids,Integer.class);
//        Integer[] a = (Integer[]) ids;
        thotelAssess.setBookIds(aa);
        thotelAssessService.deletepiliang(thotelAssess);
        JsonData jsonData = new JsonData();
        jsonData.setCode(0);
        jsonData.setMessage("删除成功");
        return jsonData;
    }

    @RequestMapping(value = "/updateByPrimaryKeySelective")
    @ResponseBody
    public JsonData updateByPrimaryKeySelective(ThotelAssess thotelAssess) {
        thotelAssessService.updateByPrimaryKeySelective(thotelAssess);
        JsonData jsonData = new JsonData();
        jsonData.setCode(0);
        jsonData.setMessage("修改成功");
        return jsonData;
    }


    @RequestMapping(value = "/deleteByPrimaryKey")
    @ResponseBody
    public JsonData deleteByPrimaryKey(ThotelAssess thotelAssess) {
        System.out.println("thotelAssess"+thotelAssess);
        thotelAssessService.deleteByPrimaryKey(thotelAssess);
        JsonData jsonData = new JsonData();
        jsonData.setCode(0);
        jsonData.setMessage("删除成功");
        return jsonData;
    }
}
